<?php

require_once 'cms/content/om/om/BaseContent.php';


/**
 * Skeleton subclass for representing a row from the 'content' table.
 *
 * 
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package cms.content.om
 */	
class Content extends BaseContent {

    private $linkCount;
    private $activeLinks;

    public function getLinkCount() {
        return $this->linkCount;
    }

    public function setLinkCount($linkCount) {
        $this->linkCount = $linkCount;
    }

    public function hydrate(ResultSet $rs, $startcol = 1)
    {
        $startcol = parent::hydrate($rs, $startcol);

        try {
            $this->linkCount = $rs->getInt($startcol);
        } catch(Exception $e) {
            ;
        }
    }

    function getActiveLinks() {
        if(is_null($this->activeLinks)) {
            require_once("ContentLinkPeer.php");
            $c = new Criteria();
            $c->add(ContentLinkPeer::CONTENT_ID, $this->getContentId());
            $c->add(ContentLinkPeer::ACTIVE, true);
            $c->addAscendingOrderByColumn(ContentLinkPeer::POSITION);
            $this->activeLinks = ContentLinkPeer::doSelect($c);
        }
        return $this->activeLinks;
    }

    function getMaxPosition() {

        $con = Propel::getConnection();
        $stmt = $con->createStatement();

        $rs = $stmt->executeQuery(
                "SELECT MAX(position) FROM content " .
                "WHERE category_id = ". $this->getCategoryId(),
                ResultSet::FETCHMODE_NUM
              );

        if($rs->next()) {
            return $rs->getInt(1);
        }
    }

    public function getDefaultContentI18n($lang) {
        require_once("ContentI18nPeer.php");
        $c = new Criteria();
        $c->add(ContentI18nPeer::CONTENT_ID, $this->getContentId());
        $c->add(ContentI18nPeer::LANGUAGE_CODE, $lang);
        return ContentI18nPeer::doSelectOne($c);
    }

} // Content
